package org.diffshop.common.valid;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.diffshop.common.annotation.ListVal;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @Author:tjf
 * @Description:
 */
public class ConstraintListValValidator implements ConstraintValidator<ListVal, Integer>{
    private HashSet<Integer> specifiedArgs = new HashSet();
    @Override
    public void initialize(ListVal constraintAnnotation) {
        int[] vals = constraintAnnotation.value();
        Arrays.stream(vals).forEach(val -> {
            specifiedArgs.add(val);
        });
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return specifiedArgs.contains(value);
    }
}
